package com.service.impl;

import com.bean.entity.PhysicalHealth;
import com.bean.pojo.PageAssistant;
import com.bean.vo.PhysicalHealthVo;
import com.dao.PhysicalHealthMapper;
import com.service.PhysicalHealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * User: 刘文雄
 * Date:2022/3/30 13:40
 * 体质健康表基础业务逻辑实现
 */
@Service
public class PhysicalHealthServiceImpl implements PhysicalHealthService {
    @Autowired
    private PhysicalHealthMapper physicalHealthMapper;
    @Override
    public int save(PhysicalHealth t) throws Exception {
        int insert = physicalHealthMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("新增体质健康数据失败");

    }
    @Override
    public int remove(PhysicalHealth t) throws Exception {
        int delete = physicalHealthMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("删除体质健康数据失败");
    }
    @Override
    public int modify(PhysicalHealth t) throws Exception {
        int update = physicalHealthMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改体质健康数据失败");
    }
    @Override
    public PhysicalHealthVo unique(PhysicalHealth t) throws Exception {
        List<PhysicalHealthVo> physicalHealthVoList = physicalHealthMapper.select(t);
        if (physicalHealthVoList.size() !=1)
            throw new Exception("没有相关信息");
        return physicalHealthVoList.get(0);
    }
    @Override
    public List<PhysicalHealthVo> query(PhysicalHealth t) {
        List<PhysicalHealthVo> physicalHealthVoList = physicalHealthMapper.select(t);
        return physicalHealthVoList;
    }
    @Override
    public PageAssistant<PhysicalHealthVo> queryByPage(Map<String, Object> map, PageAssistant<PhysicalHealthVo> pa) {
        //查询并设置总记录数
        pa.setCount(physicalHealthMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(physicalHealthMapper.selectByPage(map));
        return pa;
    }
}
